package com.macro.mall.common.util;

import lombok.extern.slf4j.Slf4j;

import java.util.Random;


@Slf4j
public class BaseIdUtil {
    /**
     * 清单行自增id数据锁名前缀-id生成
     */
    public static final String CONTRACT_DATA_CLEAN_LOCK_CLEAN_ID_NAME_PRE_SERIAL = "yzw:e:doctemplate:lock:data:clean.row.id.pre.serial";


    /**
     * id生成类
     */
    private static IdWorker worker = null;

    static Random r = new Random();

    static {
        int num = r.nextInt(50);
        log.info("serial num" + num);
        worker = new IdWorker(num);
    }

    /**
     * 获取ID
     *
     * @return String
     */
    public static Long getId() {
        return worker.nextId();
    }

    /**
     * 获取ID
     *
     * @return String
     */
    public static String getStrId() {
        return String.valueOf(getId());
    }

    private void initWorker() {
        int num = r.nextInt(50);
        log.info("serial num" + num);
        worker = new IdWorker(num);
    }
}
